<template>
  <div>
    <div>
        <el-form :model="form" label-suffix="：" ref="form" label-width="145px" :rules="rules">
            <el-row :gutter="20">
                <el-col :span="12" >
                    <el-form-item :label="$t('paperBlindTrial.firstDisciplineName')" prop="firstDisciplineName">
                        <el-input v-model="form.firstDisciplineName" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12" >
                    <el-form-item :label="$t('paperBlindTrial.secondaryDisciplineName')" prop="secondaryDisciplineCode">
                      <el-select v-model="form.secondaryDisciplineCode" placeholder="" style="width: 100%;" :disabled="viewState || subjectTwoState" v-clearreadonly filterable>
                        <el-option v-for="item in options.typeTwo" :label="item.label" :value="item.value" :key="item.value"></el-option>
                      </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12" >
                    <el-form-item :label="$t('label.schoolTerm')">
                        <el-input v-model="form.yearTermI18n" maxlength="20" :disabled="true" ></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12" >
                    <el-form-item :label="$t('achievementApply.thesisTitle')" prop="thesisTitle">
                        <el-input v-model.trim="form.thesisTitle" :maxlength="128" :disabled="viewState || paperDisabled" ></el-input>
                        <!-- <el-select
                          :disabled="viewState || paperDisabled"
                          v-model.trim="form.thesisTitle"
                          filterable
                          allow-create
                          default-first-option
                          style="width: 100%"
                          :placeholder="$t('inputPlaceholder')">
                          <el-option
                            v-for="item in thesisTitleList"
                            :key="item.value"
                            :label="item.value"
                            :value="item.value">
                          </el-option>
                        </el-select> -->
                    </el-form-item>
                </el-col>
                <el-col :span="12" class="upload_Item">
                    <el-form-item :label="$t('paperBlindTrial.paperEnName')" prop="thesisTitleEn">
                        <el-input v-model="form.thesisTitleEn" :maxlength="128" :disabled="viewState" ></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12" class="upload_Item">
                    <el-form-item :label="$t('paperBlindTrial.paperDirection')" prop="thesisResearchField">
                      <el-input v-model="form.thesisResearchField" maxlength="18" :disabled="viewState" ></el-input>
                      <div class="input_tips">{{$t('paperBlindTrial.paperDirectionTips')}}</div>
                    </el-form-item>
                </el-col>
                <el-col :span="12" class="upload_Item">
                    <el-form-item :label="$t('paperBlindTrial.paperKeyword')" prop="thesisKeyword">
                        <el-input v-model="form.thesisKeyword" maxlength="101" :disabled="viewState" ></el-input>
                        <div class="input_tips">{{$t('paperBlindTrial.paperKeywordTips')}}</div>
                    </el-form-item>
                </el-col>
                <el-col :span="12" class="upload_Item">
                    <el-form-item :label="$t('paperBlindTrial.paperLang')" prop="thesisLang">
                      <!-- <DictSelect v-model="form.thesisLang" :data="options.thesisLang" :disabled="viewState" ></DictSelect> -->
                      <el-select
                        :disabled="viewState"
                        v-model.trim="form.thesisLang"
                        filterable
                        style="width: 100%"
                        :placeholder="$t('inputPlaceholder')"
                        v-clearreadonly>
                        <el-option
                          v-for="item in options.thesisLang"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="12" class="upload_Item">
                    <el-form-item :label="$t('paperBlindTrial.paperItem')" prop="paperItem">
                      <el-upload
                        v-if="!viewState"
                        ref="paperUplad"
                        :headers="{'X-Token': $store.state.session.sessionid}"
                        :action="uploadAction"
                        :data="{bucketname: 'face', folderpath: 'file'}"
                        :limit="1"
                        accept=".pdf"
                        :before-upload="(file)=>beforeUpload(file, 'LW.pdf', 'paperItemList', 'paperItem','BLIND_REVIEW_PAPER', 'pdf')"
                        :on-exceed="handleExceed"
                        :file-list="paperItemList"
                        :on-remove="(file, fileList)=>removeFunc(file, fileList, 'paperItem')"
                        :on-success="(res,file,fileList)=>uploadDone(res, file,'paperItem','BLIND_REVIEW_PAPER', 'pdf', 'LW.pdf')">
                        <el-button size="small" type="primary">{{$t('common.btn.clickUpload')}}</el-button>
                        <span slot="tip" class="el-upload__tip tips_margin">{{$t('paperBlindTrial.pdfFileTips')}}</span>
                      </el-upload>
                      <div v-else class="link_style" @click="downLoadFunc(form.paperItem)">{{form.paperItem && form.paperItem.attachName}}</div>
                    </el-form-item>
                </el-col>
                <el-col :span="12" class="upload_Item">
                    <el-form-item :label="$t('paperBlindTrial.summaryItem')" prop="summaryItem">
                      <el-upload
                        v-if="!viewState"
                        ref="abstractUplad"
                        :headers="{'X-Token': $store.state.session.sessionid}"
                        :action="uploadAction"
                        :data="{bucketname: 'face', folderpath: 'file'}"
                        :limit="1"
                        accept=".txt"
                        :before-upload="(file)=>beforeUpload(file, 'ZY.txt', 'summaryItemList', 'summaryItem','BLIND_SUMMARY', 'text')"
                        :on-exceed="handleExceed"
                        :file-list="summaryItemList"
                        :on-remove="(file, fileList)=>removeFunc(file, fileList, 'summaryItem')"
                        :on-success="(res,file,fileList)=>uploadDone(res, file,'summaryItem','BLIND_SUMMARY', 'text', 'ZY.txt')">
                        <el-button size="small" type="primary">{{$t('common.btn.clickUpload')}}</el-button>
                        <span slot="tip" class="el-upload__tip tips_margin">{{$t('paperBlindTrial.txtFileTips')}}</span>
                      </el-upload>
                      <div v-else class="link_style" @click="downLoadFunc(form.summaryItem)">{{form.summaryItem && form.summaryItem.attachName}}</div>
                    </el-form-item>
                </el-col>
                <el-col :span="12" class="upload_Item" >
                    <el-form-item :label="$t('paperBlindTrial.profileItem')" prop="profileItem">
                      <el-upload
                        v-if="!viewState"
                        ref="tableUplad"
                        :headers="{'X-Token': $store.state.session.sessionid}"
                        :action="uploadAction"
                        :data="{bucketname: 'face', folderpath: 'file'}"
                        :limit="1"
                        accept=".pdf"
                        :before-upload="(file)=>beforeUpload(file, 'JKB.pdf', 'profileItemList', 'profileItem','BLIND_PROFILE', 'pdf')"
                        :on-exceed="handleExceed"
                        :file-list="profileItemList"
                        :disabled="!switchObj.shortInstUploadFlag || switchObj.shortInstUploadFlag === 'N'"
                        :on-remove="(file, fileList)=>removeFunc(file, fileList, 'profileItem')"
                        :on-success="(res,file,fileList)=>uploadDone(res, file,'profileItem','BLIND_PROFILE', 'pdf', 'JKB.pdf')">
                        <el-button size="small" type="primary" :disabled="!switchObj.shortInstUploadFlag || switchObj.shortInstUploadFlag === 'N'" >{{$t('common.btn.clickUpload')}}</el-button>
                        <span slot="tip" class="el-upload__tip tips_margin">{{$t('paperBlindTrial.pdfFileTips')}}</span>
                    </el-upload>
                      <div v-else class="link_style" @click="downLoadFunc(form.profileItem)">{{form.profileItem && form.profileItem.attachName}}</div>
                    </el-form-item>
                </el-col>
                <el-col :span="12" class="upload_Item">
                    <el-form-item :label="$t('paperBlindTrial.selfFormItem')" prop="selfFormItem">
                      <el-upload
                        v-if="!viewState"
                        ref="selfTableUplad"
                        :headers="{'X-Token': $store.state.session.sessionid}"
                        :action="uploadAction"
                        :data="{bucketname: 'face', folderpath: 'file'}"
                        :limit="1"
                        accept=".pdf"
                        :before-upload="(file)=>beforeUpload(file, 'ZPB.pdf', 'selfFormItemList', 'selfFormItem','BLIND_SELF_EVALUATION', 'pdf')"
                        :on-exceed="handleExceed"
                        :file-list="selfFormItemList"
                        :disabled="!switchObj.selfAssUploadFlag || switchObj.selfAssUploadFlag === 'N'"
                        :on-remove="(file, fileList)=>removeFunc(file, fileList, 'selfFormItem')"
                        :on-success="(res,file,fileList)=>uploadDone(res, file,'selfFormItem','BLIND_SELF_EVALUATION', 'pdf', 'ZPB.pdf')">
                        <el-button size="small" type="primary" :disabled="!switchObj.selfAssUploadFlag || switchObj.selfAssUploadFlag === 'N'" >{{$t('common.btn.clickUpload')}}</el-button>
                        <span slot="tip" class="el-upload__tip tips_margin">{{$t('paperBlindTrial.pdfFileTips')}}</span>
                      </el-upload>
                      <div v-else class="link_style" @click="downLoadFunc(form.selfFormItem)">{{form.selfFormItem && form.selfFormItem.attachName}}</div>
                    </el-form-item>
                </el-col>
                <el-col :span="12" class="upload_Item" >
                    <el-form-item :label="$t('paperBlindTrial.otherItem')" prop="otherItem">
                      <el-upload
                        v-if="!viewState"
                        ref="otherInfoUplad"
                        :headers="{'X-Token': $store.state.session.sessionid}"
                        :action="uploadAction"
                        :data="{bucketname: 'face', folderpath: 'file'}"
                        :limit="1"
                        accept=".zip"
                        :before-upload="(file)=>beforeUpload(file, 'QT.zip', 'otherItemList', 'otherItem','BLIND_OTHER', 'zip')"
                        :on-exceed="handleExceed"
                        :file-list="otherItemList"
                        :disabled="!switchObj.otherUploadFlag || switchObj.otherUploadFlag === 'N'"
                        :on-remove="(file, fileList)=>removeFunc(file, fileList, 'otherItem')"
                        :on-success="(res,file,fileList)=>uploadDone(res, file,'otherItem','BLIND_OTHER', 'zip', 'QT.zip')">
                        <el-button size="small" type="primary" :disabled="!switchObj.otherUploadFlag || switchObj.otherUploadFlag === 'N'">{{$t('common.btn.clickUpload')}}</el-button>
                        <span slot="tip" class="el-upload__tip tips_margin">{{$t('paperBlindTrial.zipFileTips')}}</span>
                      </el-upload>
                      <div v-else class="link_style" @click="downLoadFunc(form.otherItem)">{{form.otherItem && form.otherItem.attachName}}</div>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
  </div>
</template>

<script>
import { applyGetStu } from "common/src/api/preDefense";
import { getPaperTitle } from "common/src/api/paperAchievements";
import { applyGetSwitchInfo, commonUpload, applyAddOrEdit, applyGetdetail, commonDownload } from "common/src/api/paperBlindTrial";
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
import { queryDic } from 'common/src/api/dictionary';
// 第一个接口不带分页，第二个带分页
import { getGraduateDegreePage } from "common/src/api/resource/course";
import mixin from 'common/src/mixins/index';
export default {
    components: {},
    mixins: [commonMixins,mixin],
    props: {
      // 表单禁用状态
      viewState: {
        type: Boolean,
        default: false
      },
      yearTerms: {
        type: Object,
        default: {}
      },
      row: {
        type: Object,
        default: {}
      }
    },
    data() {
        return {
            uploadAction: commonUpload,
            form: {
              thesisTitle: '', // 论文题目
              firstDisciplineName: '', // 一级学科名称
              firstDisciplineCode: '', // 一级学科code
              secondaryDisciplineName: '', // 二级学科名称
              secondaryDisciplineCode: '', // 二级学科code
              yearTerm: '',
              yearTermI18n: '',
              thesisTitleEn: '', // 论文英文题目
              thesisLang: '', // 论文撰写语种
              paperItem: '', // 盲审论文
              summaryItem: '', // 摘要
              profileItem: '', // 简况表
              selfFormItem: '',// 自评表
              otherItem: '',   //其他
            },
            rules: {
              thesisTitle: [
                {required: true, validator: this.validateInput, trigger: 'change' },
              ],
              thesisTitleEn: [
                {required: true, validator: this.validateInput, trigger: 'change' },
              ],
              firstDisciplineName: [
                { required: true, message: this.$t('paperBlindTrial.firstDisciplineNameTips'), trigger: 'change' },
              ],
              secondaryDisciplineCode: [
                { required: true, message: this.$t('common.pla.pleaseSelect'), trigger: 'change' },
              ],
              thesisLang: [
                { required: true, message: this.$t('common.pla.pleaseSelect'), trigger: 'change' },
              ], // 论文撰写语种
              paperItem: [
                { required: true, validator: (rule, value, callback)=>this.validateFile(rule, value, callback, 'paperUplad'), trigger: 'change' },
              ], // 盲审论文
              summaryItem: [
                { required: true, validator: (rule, value, callback)=>this.validateFile(rule, value, callback, 'abstractUplad'), trigger: 'change' },
              ], // 摘要
              profileItem: [
                { required: true, validator: (rule, value, callback)=>this.validateFile(rule, value, callback, 'tableUplad'), trigger: 'change' },
              ], // 简况表
              selfFormItem: [
                { required: true, validator: (rule, value, callback)=>this.validateFile(rule, value, callback, 'selfTableUplad'), trigger: 'change' },
              ],// 自评表
              otherItem: [
                { required: true, validator: (rule, value, callback)=>this.validateFile(rule, value, callback, 'otherInfoUplad'), trigger: 'change' },
              ],   //其他
              // 论文关键词，用中文分号分隔，总长度不超过100字
              thesisKeyword: [
                { required: true, validator: this.validateKeyword, trigger: 'change' },
                { min: 0, max: 100, message: this.$t('paperBlindTrial.lessThenHundred'), trigger: 'change' }
              ],
              // 研究方向 最多8个字，最多两个，用中文分号分隔总长度不超过17个字
              thesisResearchField: [
                { required: true, validator: this.validateReserach, trigger: 'change' },
                { min: 0, max: 17, message: this.$t('paperBlindTrial.lessThenSeventeen'), trigger: 'change' }
              ],
            },
            options: {
              thesisLang: [],
              typeOne: [], // 一级学科
              typeTwo: [], // 二级学科
            },
            audits: {
              msg: '',
              staus: ''
            },
            switchObj: {  // 控制开关对象
              shortInstUploadFlag: 'N', // 简况表上传开关：
              selfAssUploadFlag: 'N', // 自评表上传开关：
              otherUploadFlag: 'N' // 其他材料上传开关：
            },
            currentUser: {},
            paperItemList: [], // 盲审论文
            summaryItemList: [], // 摘要
            profileItemList: [], // 简况表
            selfFormItemList: [], // 自评表
            otherItemList: [], // 其他
            majorObj: {},
            subjectTwoState: false,
            stuNo: '',
            paperDisabled: false,
            thesisTitleList: []
        };
    },
    computed: {

    },
    created() {

    },
    mounted() {
      // id存在则查详情数据
      this.getUserInfo();
      this.currentUser = this.global.currentUser;
      this.getDic(); // 获取撰写语种值
      this.getSwitchDetail(); // 获取开关控制信息
      this.getTitle(); // 获取论文题目
      if (this.row.id || this.row.applyId) {
        this.getDetail();
      } else {
        // 新增时用修改数据不再查询
        this.form.yearTerm = this.yearTerms.id;
        this.form.yearTermI18n = this.yearTerms.fullName;
      }

    },
    methods: {
      // 获取一级学科/专业领域
      getListData (code) {
          getGraduateDegreePage({
          condition: code,
          pageNum_: 1,
          pageSize_: 100
        }).then(res => {
          if (res.code == 200) {
            let resultData = res.data.list;
            this.options['typeTwo'] = resultData.map(c => {
              return {
                  label: c.name,
                  value: c.code+','+c.name,
              };
            });
            if (resultData.length > 0) { // 如果当前专业为一级学科，则需要查询二级学科数据
              this.form.firstDisciplineName = resultData[0].majorName;
              this.form.firstDisciplineCode = resultData[0].majorCode;
              this.subjectTwoState = false;
              this.form.secondaryDisciplineCode = this.majorObj.code+','+this.majorObj.name; // 二级学科名称
            }
          }
        });
      },
      // 获取用户信息
      getUserInfo () {
        applyGetStu()
        .then(res => {
          this.stuNo = res.data.stuNo;
          this.majorObj = { code: res.data.majorId, name: res.data.majorName };
          // 没有专业信息或者非新增时都不需要查询专业信息
          if (!res.data.majorId || res.data.majorId == '' || this.row.applyId) {
            return;
          }
          let typeOneCode = res.data.majorId.slice(0, 4);
          this.getListData(typeOneCode); // 一级学科
        });
      },
      getDic() { // val: {  X_PYCC: 'trainingLevel',   G_ZY: 'profession'} // 专业
        const data = {
          lang: this.$store.getters.language || 'cn',
          type: 'allChild',
          keys: ['WRITE_PAPER_LANGUAGE']
        };
        return new Promise((resolve, reject) => {
          queryDic(data).then(res => {
            if (res.code === 200) {
              this._fill('thesisLang', res.data['WRITE_PAPER_LANGUAGE']);
              if (this.currentUser.faculty !== "000268") { // 不是外国语学院只有中、英、德、法语
                this.options.thesisLang = this.options.thesisLang.filter(v => v.value !== 'it'
                && v.value !== 'ja' && v.value !== 'ru');
              }
            }
            resolve(this.options);
          }).catch((err) => {
            reject(err);
          });
        });
      },
      save(type) {
        this.$refs.form.validate((valid) => {
          if (valid) {
            let paramArr = [];
            if (!this.form.paperItem || !this.form.summaryItem
            || (this.switchObj.shortInstUploadFlag == 'Y' && !this.form.profileItem)
            || (this.switchObj.selfAssUploadFlag == 'Y' && !this.form.selfFormItem)
            || (this.switchObj.otherUploadFlag == 'Y' && !this.form.otherItem)) {
              this.$message.error(this.$t('paperBlindTrial.fileWaitTips'));
              return;
            }
            paramArr = [
              this.form.paperItem || {}, // 盲审论文
              this.form.summaryItem || {}, // 摘要
              this.form.profileItem || {}, // 简况表
              this.form.selfFormItem || {},// 自评表
              this.form.otherItem || {},   //其他
            ];
            paramArr = paramArr.filter(v=> v.attachName && v.attachName !== '');
            let secondItem = this.form.secondaryDisciplineCode;
            if (secondItem.includes(',')) {
              secondItem = secondItem.split(',');
            }
            let param = {
              firstDisciplineName: this.form.firstDisciplineName, // 一级学科名称
              firstDisciplineCode: this.form.firstDisciplineCode, // 一级学科code
              secondaryDisciplineName: type === 'edit' ? this.form.secondaryDisciplineName : secondItem[1], // 二级学科名称
              secondaryDisciplineCode: type === 'edit' ? this.form.secondaryDisciplineCode : secondItem[0], // 二级学科code
              concealEvaApplyInfoT: {
                id: this.row.applyId,
                yearTerm: this.form.yearTerm,
                thesisTitle: this.form.thesisTitle,
                "thesisKeyword":  this.form.thesisKeyword,  //	论文关键词
                "thesisTitleEn":  this.form.thesisTitleEn, 	//论文英文题目
                "thesisResearchField": this.form.thesisResearchField,  //论文研究方向
                "thesisLang": this.form.thesisLang,	//论文撰写语种
              },
              concealEvaAttachTs: paramArr
            };
            applyAddOrEdit(param).then(res=> {
              if (res.code === 200) {
                if (type && type === 'edit') {
                  this.$message.success(this.$t('achievementApply.editSuccessfully'));
                } else {
                  this.$message.success(this.$t('paperBlindTrial.applySuccess'));
                }
                this.back();
              }
            });
          }
        });
      },
      back() {
        this.$emit('emit:back');
      },
      audit(type) { // 审核
        this.audits.staus = type;
        this.$emit('emit:complete');
      },
      // 根据申请id查询详情
      getDetail () {
        applyGetdetail(this.row.applyId).then(res => {
          let uploadArr = res.data.concealEvaAttachTs;
          this.form = Object.assign({}, res.data.concealEvaApplyInfoT);
          this.form.firstDisciplineCode = res.data.firstDisciplineCode || '';
          this.form.firstDisciplineName = res.data.firstDisciplineName || '';
          this.form.secondaryDisciplineCode = res.data.secondaryDisciplineCode || '';
          this.form.secondaryDisciplineName = res.data.secondaryDisciplineName || '';
          let secondItem = { label: this.form.secondaryDisciplineName, value: this.form.secondaryDisciplineCode };
          this.options.typeTwo.push(secondItem);
          this.subjectTwoState = true; // 编辑的时候学科方向不能修改
          this.$emit('approvelParam', res.data.concealEvaApplyInfoT);
          this.form.paperItem = uploadArr.filter(v => v.businessType === 'BLIND_REVIEW_PAPER')[0]; // 盲审论文
          this.paperItemList = this.form.paperItem && [{name: this.form.paperItem.attachName, size: parseInt(this.form.paperItem.attachSize)}];
          this.form.summaryItem = uploadArr.filter(v => v.businessType === 'BLIND_SUMMARY')[0]; // 摘要
          this.summaryItemList = this.form.summaryItem && [{name: this.form.summaryItem.attachName, size: parseInt(this.form.summaryItem.attachSize)}];
          this.form.profileItem = uploadArr.filter(v => v.businessType === 'BLIND_PROFILE')[0]; // 简况表
          this.profileItemList = this.form.profileItem && [{name: this.form.profileItem.attachName, size: parseInt(this.form.profileItem.attachSize)}];
          this.form.selfFormItem = uploadArr.filter(v => v.businessType === 'BLIND_SELF_EVALUATION')[0];// 自评表
          this.selfFormItemList = this.form.selfFormItem && [{name: this.form.selfFormItem.attachName, size: parseInt(this.form.selfFormItem.attachSize)}];
          this.form.otherItem = uploadArr.filter(v => v.businessType === 'BLIND_OTHER')[0];   //其他
          this.otherItemList = this.form.otherItem && [{name: this.form.otherItem.attachName, size: parseInt(this.form.otherItem.attachSize)}];
        });
      },
      // 上传文件前的判断
      beforeUpload (file, suffix, fileList, formKey, businessType, attachType) {
        const isPDF = file.type === 'application/pdf';
        const isTXT = file.type === 'text/plain';
        const isZIP = file.type === 'application/x-zip-compressed';

        if (suffix.includes('.pdf') && !isPDF) {
          this.$message.error(this.$t('paperBlindTrial.pdfFileTips'));
          return false;
        }
        if (suffix.includes('.txt') && !isTXT) {
          this.$message.error(this.$t('paperBlindTrial.txtFileTips'));
          return false;
        }
        if (suffix.includes('.zip') && !isZIP) {
          this.$message.error(this.$t('paperBlindTrial.zipFileTips'));
          return false;
        }
        return true;
        // const copyFile = new File([file], '10247'+'_'+this.stuNo+'_'+suffix);
        // this[fileList] = [{ name: copyFile.name, size: copyFile.size }];
        // this.uploadFile(copyFile, formKey, businessType, attachType);
        // return false;
      },
      // 创建上传文件的参数
      uploadFile(file, formKey, businessType, attachType) {
        const formdata = new FormData()
        formdata.append('file', file)
        formdata.append('bucketname', 'face')
        formdata.append('folderpath', 'file')
        this.postForm(formdata, file, formKey, businessType, attachType)
      },
      // 调用接口上传文件
      postForm(formdata, file, formKey, businessType, attachType) {
        uploadFilePlan(formdata).then(res => {
          if (res.code == 200) {
            let jsons = {
              businessType: businessType,
              attachName: file.name,
              attachSize: file.size,
              attachType: attachType,
              attachPath: Object.values(res.data)[0].objectkey
            };
            this.form[formKey] = jsons;
            this.$refs.form.validateField([formKey]);
          }
        }).catch((err) => {
          this.$message.error(err.message || this.$t('paperBlindTrial.fileFailMsg'))
        })
      },
      handleExceed(files, fileList) {
        this.$message.warning(this.$t('paperBlindTrial.oneFileTips'));
      },
      // 校验关键字
      validateKeyword (rule, value, callback) {
        if (!value || value.length === 0) {
          return callback(new Error(this.$t('inputPlaceholder')));
        }
        if (value.includes('$')) {
          return callback(new Error(this.$t('achievementApply.specilTips')));
        }
        return callback();
      },
      // 校验研究方向
      validateReserach (rule, value, callback) {
        if (!value || value.length === 0) {
          return callback(new Error(this.$t('inputPlaceholder')));
        }
        let itemList = value.split('；');
        if (value.includes('$')) {
          return callback(new Error(this.$t('achievementApply.specilTips')));
        }
        if (itemList.length > 2) {
          return callback(new Error(this.$t('paperBlindTrial.twoDirctionTips')));
        }
        if ((itemList[0] && itemList[0].length > 8) || (itemList[1] && itemList[1].length > 8)) {
          return callback(new Error(this.$t('paperBlindTrial.reserachTips')));
        }
        return callback();
      },
      // 获取论文题目
      getTitle () {
        let param = {
          stuNo: this.currentUser.uid,
          yearTerm: this.yearTerms.id
        };
        getPaperTitle(param)
        .then(res=>{
          if (res.data.length > 0) {
            this.paperDisabled = true;
            // 新增时取第一个论文题目，修改时根据获取的详情赋值
            if (!this.row.applyId) {
              this.form.thesisTitle = res.data[0].paperName;
            }
            res.data.forEach(item=>{
              let obj = { value: item.paperName, label: item.paperName };
              this.thesisTitleList.push(obj);
            });
          } else {
            this.thesisTitleList = [];
            this.paperDisabled = false;
          }
        });
      },
      // 获取预评审控制开关详情
      getSwitchDetail () {
        let param = {
          "pageNum_": 1,
          "pageSize_": 10,
          "condition": {
            "academyCode": this.currentUser.faculty,	//根据学院编号查询
          }
        };
        applyGetSwitchInfo(param).then(res=>{
          if (res.code === 200) {
            let resultObj = (res.data.list && res.data.list[0])
            || {
              shortInstUploadFlag: 'N', // 简况表上传开关：
              selfAssUploadFlag: 'N', // 自评表上传开关：
              otherUploadFlag: 'N' // 其他材料上传开关：
            };
            this.switchObj = resultObj;
            if (!this.switchObj.otherUploadFlag || this.switchObj.otherUploadFlag === 'N') {
              this.rules.otherItem = [];
            }
            if (!this.switchObj.shortInstUploadFlag || this.switchObj.shortInstUploadFlag === 'N') {
              this.rules.profileItem = [];
            }
            if (!this.switchObj.selfAssUploadFlag || this.switchObj.selfAssUploadFlag === 'N') {
              this.rules.selfFormItem = [];
            }
          }
        });
      },
      uploadDone(res, file, formKey, businessType, attachType, suffix) {
        let jsons = {
          businessType: businessType,
          attachName: '10247'+'_'+this.stuNo+'_'+suffix,
          attachSize: file.size,
          attachType: attachType,
          attachPath: Object.values(res.data)[0].objectkey
        };
        this.form[formKey] = jsons;
        this.$refs.form.validateField([formKey]);
      },
      // 校验上传文件
      validateFile (rule, value, callback, uploadRef) {
        if (!this.$refs[uploadRef].uploadFiles.length) {
          return callback(new Error(this.$t('paperBlindTrial.emptyFileTips')));
        } else {
          return callback();
        }
      },
      // 下载附件方法
      downLoadFunc (fileInfo) {
        let fileSuffix = fileInfo.attachName.split('.')[1];
        let fileType = fileSuffix == 'pdf' ? 'application/pdf' : fileSuffix == 'zip' ? 'application/x-zip-compressed' : 'text/plain';
        window.open("/api/designservice/resultPublish/downLoadMore?path=" + fileInfo.attachPath + '&fileName=' + fileInfo.attachName);
        // commonDownload(fileInfo.attachPath, fileInfo.attachName, fileType);
      },
      // 文件删除方法
      removeFunc(file, fileList, formKey) {
        if (fileList.length === 0) {
          this.form[formKey] = null;
        }
      }
    }
};
</script>

<style scoped lang="scss">
.con {
    &_footer {
        display: flex;
        flex-direction: row-reverse;
        &_sure {
            margin-left: 20px;
        }
    }
    &_footer1 {
        padding-left: 120px;
    }
}
.link_style {
  cursor: pointer;
  color: #3A7FE8;
}
.tips_margin {
  margin-left: 20px;
}
.upload_Item {
  height: 85px;
}
.input_tips {
  color: #BDBEBE;
  line-height: 18px;
}
</style>
